/**
 * @file 简易vuex，用来同步组件、页面之间通用数据的通信
 * @author michaelZ
 */
import Vue from 'vue';

import { UserInfo } from '@/types';
import { Season } from '@/types/season';
import { Activity } from '@/types/activity';

// 全局数据中心，利用Vue.observable使其具有响应式特性，触发数据的流动
export const store = Vue.observable({
  isLogin: false,
  userInfo: {} as UserInfo,
  activity: {} as any,
  season: {} as Season,
  seasons: [{}] as Season[]
});

// 更改store里的数据，且只能从这里改
export const mutations = {
  // 更新登录状态
  updateLoginStatus(status: boolean) {
    store.isLogin = status;
  },

  // 更新用户信息
  updateUserInfo(userInfo: UserInfo): void {
    store.userInfo = userInfo;
  },

  // 更新当前活动信息
  updateActivity(activity: Activity): void {
    store.activity = activity;
  },

  updateSeason(season: Season): void {
    store.season = season;
  },

  updateSeasons(seasons: Season[]): void {
    store.seasons = seasons;
  }
};

Vue.prototype.$$store = store;
Vue.prototype.$$mutations = mutations;
